package com.chuangke.common.report;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;

@SuppressWarnings("rawtypes")
public class JasperReportData {

	private Map<String, Object> parameters = new HashMap<>();
	private List details;

	public JasperReportData putParam(String key, Object value) {
		parameters.put(key, value);
		return this;
	}

	public Map<String, Object> getParameters() {
		return parameters != null ? parameters:new HashMap<>();
	}

	public void setParameters(Map<String, Object> parameters) {
		this.parameters = parameters;
	}

	public List getDetails() {
		return details;
	}

	public void setDetails(List details) {
		this.details = details;
	}

	public JRDataSource getDetailDataSource() {
		if (null != details && !details.isEmpty()) {
			return new JRBeanCollectionDataSource(details);
		} else {
			return new JREmptyDataSource();
		}
	}

}
